unit main;

interface

uses
  Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,
  Vcl.Controls, Vcl.Forms, Vcl.Dialogs, registry, Vcl.StdCtrls, IdSocketHandle,
  IdBaseComponent, IdComponent, IdUDPBase, IdUDPServer, IdContext,
  IdCustomTCPServer, IdTCPServer, IdCmdTCPServer, IdCommandHandlers;


type
  TForm1 = class(TForm)
    IdCmdTCPServer1: TIdCmdTCPServer;
    procedure IdCmdTCPServer1Connect(AContext: TIdContext);
    procedure FormCreate(Sender: TObject);
    procedure IdCmdTCPServer1CommandHandlers1Command(ASender: TIdCommand);
    procedure IdCmdTCPServer1CommandHandlers2Command(ASender: TIdCommand);
    procedure IdCmdTCPServer1CommandHandlers0Command(ASender: TIdCommand);
    procedure IdCmdTCPServer1CommandHandlers3Command(ASender: TIdCommand);
  private
    { Private declarations }
    v: boolean;
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure SWP(PicPath: string);
begin
if not SystemParametersInfo(SPI_SETDESKWALLPAPER, 0, pChar(PicPath), SPIF_SENDCHANGE) then
    RaiseLastOSError;
end;


procedure TForm1.FormCreate(Sender: TObject);
begin
  v:=true;
end;

procedure TForm1.IdCmdTCPServer1CommandHandlers0Command(ASender: TIdCommand);
begin
//  ASender.Disconnect := True;
  Halt(1);
end;

procedure TForm1.IdCmdTCPServer1CommandHandlers1Command(ASender: TIdCommand);
begin
  //ASender.Disconnect := True;
end;

procedure TForm1.IdCmdTCPServer1CommandHandlers2Command(ASender: TIdCommand);
var
  e, v: Integer;
  fname: string;
begin
  if ASender.Params.Count <> 1 then
    ASender.Reply.SetReply(500,'Parametermegfogalmazas pontatlan')
  else begin
    fname := ASender.Params[0];
    val(fname,v,e);
    if e = 0 then
    begin
      fname := format('C:\Windows\Normal%.4d.jpg',[v]);
      SWP(fname);
    end;
  end;
end;

procedure TForm1.IdCmdTCPServer1CommandHandlers3Command(ASender: TIdCommand);
var
  e, v: Integer;
  fname: string;
begin
  if ASender.Params.Count <> 1 then
    ASender.Reply.SetReply(500,'Parametermegfogalmazas pontatlan')
  else begin
    fname := ASender.Params[0];
    val(fname,v,e);
    if e = 0 then
    begin
      fname := format('C:\Windows\WILD%.4d.jpg',[v]);
      SWP(fname);
    end;
  end;
end;

procedure TForm1.IdCmdTCPServer1Connect(AContext: TIdContext);
begin
  beep;
end;

end.
